package com.xuecheng.media.mapper.provider;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.jdbc.SQL;

/**
 * @author luhao
 * @ClassName MediaProcessProvider.java
 * @Description
 * @createTime 2023/8/14
 */
public class MediaProcessProvider {
    private static final String MEDIA_PROCESS_TABLE_NAME = "media_process";

    private static final Integer NO_DISPOSE = 1;
    private static final Integer FAILED = 3;

    private static final Integer FAIL_COUNT = 3;
    public String selectListByShardIndex(@Param("shardingIndex") Integer shardingIndex,
                                         @Param("shardingTotal") Integer shardingTotal,
                                         @Param("total")Integer total){

       return new SQL().SELECT("id", "file_id", "filename", "bucket", "file_path", "status",
                        "create_date", "finish_date", "url", "errormsg", "fail_count").FROM(MEDIA_PROCESS_TABLE_NAME)
                .WHERE("id % #{shardingTotal} = #{shardingIndex}").
                AND().WHERE("(status = " + NO_DISPOSE + " or status = " + FAILED +")")
               .AND().WHERE("fail_count < " + FAIL_COUNT).LIMIT(total).toString();
    }
}
